<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  #canvas {
    border: 1px solid;
  }
</style>

<body>
  <canvas id="canvas" width="400" height="400"></canvas>
</body>
<script>



  function draw() {
    var elem = document.getElementById("canvas");
    if (elem instanceof HTMLCanvasElement) {
      let ctx = elem.getContext("2d");
      // 二次贝塞尔曲线
      ctx.beginPath();
      ctx.moveTo(75, 25);
      ctx.quadraticCurveTo(25, 25, 25, 62.5);
      ctx.quadraticCurveTo(25, 100, 50, 100);
      ctx.quadraticCurveTo(50, 120, 30, 125);
      ctx.quadraticCurveTo(60, 120, 65, 100);
      ctx.quadraticCurveTo(125, 100, 125, 62.5);
      ctx.quadraticCurveTo(125, 25, 75, 25);
      ctx.stroke();

      // 画一个圆角方块
      roundedRect(ctx, 40, 200, 100, 100, 15)

    }


  }
  draw();


  function roundedRect(ctx, x, y, width, height, radius) {
    if (ctx instanceof CanvasRenderingContext2D) {
      ctx.beginPath();
      ctx.moveTo(x+radius, y);
      ctx.quadraticCurveTo(x, y, x , y + radius);
      // 先画左侧竖线
      ctx.lineTo(x,y+height-radius);
      // 拐个角
      ctx.quadraticCurveTo(x, y + height, x + radius, y + height);
      ctx.lineTo(x+width-radius,y+height)
      ctx.quadraticCurveTo(x + width, y + height, x + width, y + height - radius);
      ctx.lineTo(x+width,y + radius);
      ctx.quadraticCurveTo(x + width, y, x + width - radius, y);
      ctx.closePath()
      // ctx.lineTo(x,y)
      ctx.stroke();
    }


  }
</script>

</html>